<template><view>
  <view class="errormsgDiv" v-if="nodata">
    <view class="errormsg">\（￣︶￣）/</view>
    <view class="errormsg2">没有相关数据</view>
  </view>
  
	<view class="cu-list menu-avatar" style="margin-top: 0;" v-else>
		<view class="cu-item"  :key="index"  v-for="(item,index) in items"  @click="jump(item.type,item.id)">
			<view class="cu-avatar round lg" :style="'background-image:url('+item.cover+'?imageMogr2/thumbnail/500x);'"></view>
			<view class="content">
				<view class="text-grey">
					<view class="text-cut">{{item.title}}</view>
				</view>
				<view class="text-gray text-sm flex">
					<view class="text-cut">
						 
						{{item.addtime}}
					</view>
				</view>
			</view>
			<view class="action">
				<view class="text-grey text-xs">
					<view class="cu-tag round bg-blue  text-xs" v-if="item.type=='event'">活动</view>
					<view class="cu-tag round bg-orange  text-xs" v-else-if="item.type=='vote'">投票</view>
					<view class="cu-tag round bg-green  text-xs" v-else>文章</view>
				</view>
				<!-- <view class="cu-tag round bg-grey sm" v-if="item.comment_count">{{item.comment_count}}</view> -->
			</view>
		</view>

	</view>



	 
</view>

</template>
<script>
	import beeApp from '../../beeApp.js'
	export default {
		data() {
			return {
				items: [],
				page: 1,
				mounted: 0,
				groupData:{},
				nodata:0,
				loadding:0,
				userInfo:{},
				lastpage:0,
				pid:0,
				addText:'创建工单'
			}
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		      console.log(res.target)
		    }
		  },
		onLoad(option) {
          // beeApp.alert("yiqwyei");
		  if(option.pid){
			  this.pid = option.pid;
			  this.getPidData();
		  }
		  
		  
		  // if(this.pid ==91){
			 //   uni.setNavigationBarTitle({
			 //  	 title: '我的工单'
			 //  })
		  // }else if(this.pid ==94){
			 //  uni.setNavigationBarTitle({
			 //  	 title: '投诉与建议'
			 //  })
			 //  this.addText = "投诉与建议";
		  // }
		  //
		    if(option.title){
				this.title= option.title;
		    uni.setNavigationBarTitle({
		   	 title: option.title
		   })
		   }
		 this.getTopicList();
		  
		  
		},
		onShow:function(){
			var reload = beeApp.getPageData("pages/user/topics","reload");
			if(reload==1){
				beeApp.setPageData("pages/user/topics",{reload:0});
				this.getTopicList(1);
			}
		},
		onReachBottom() {
			this.getTopicList();
		},
		onPullDownRefresh() { 
			this.getTopicList(1);
			uni.stopPullDownRefresh();
		},
		methods: {
		 getPidData:function(){
			 var that = this;
			 beeApp.api("/sns/group/find", {
				 id:this.pid
			 }, function(res) {
						 
                        if (res.code != 200) {
                            beeApp.alert(res.msg);
                            return;
                        }
                        that.groupData = res.data;
						if(!that.title){
							uni.setNavigationBarTitle({
								 title: that.groupData.value
							})
						}
						
                        
                    });
		 },
		  getTopicList:function(reload=0){
			  var _this = this;
			  if(reload==1){
				  this.page=1;
				   this.loadding=0;
				  this.lastpage=0;
				  this.items=[];
			  }
			  var params = {
				    page: this.page,
					pid:this.pid
			   };
			 if ( this.loadding ==1 || this.lastpage==1) {
				   return false;
			   }
			   _this.loadding=1;
			   beeApp.api("/sns/topic/list", params, function(res) {
						_this.loadding=0;
                        if (res.code != 200) {
                            beeApp.alert(res.msg);
                            return;
                        }
                        // console.log(res);
                        if (res.data.list.length === 0) {
                            _this.lastpage = 1;
                        }

                        var items = _this.items;
                        _this.items = items.concat(res.data.list);
                        _this.page++;
                        if(_this.items.length === 0){
                            _this.nodata=1;
                        }else{
							_this.nodata=0;
						}
                    });
		  },
		  add:function(){
			  if(this.pid==91){
				   uni.navigateTo({
						url:"/pages/topic/addworkorder"
					})
			  }else if(this.pid==94){
				   uni.navigateTo({
						url:"/pages/topic/report"
					})
			  }
			 		
		  },
		  jump:function(type,id){
              if(type=='vote'){
					uni.navigateTo({
						url:"/pages/topic/topic_vote?id="+id
					})			
               }else if(type=='event'){
				   uni.navigateTo({
						url:"/pages/topic/topic_event?id="+id
					})	
			   }else{
                    uni.navigateTo({
						url:"/pages/topic/detail?id="+id
					})	
                }
            },
	   }
		
}
</script>


<style>
</style>
